package xyz.lwm.lazycat.aop;

import xyz.lwm.lazycat.aop.support.ProxyUtil;
import xyz.lwm.lazycat.beans.BeanPostProcessor;
import xyz.lwm.lazycat.beans.BeansException;

import java.util.List;

/**
 * AOP 创建
 *
 * @author lwm
 */
class AopBeanPostProcessor implements BeanPostProcessor {

    private final List<Aspect> aspects;

    public AopBeanPostProcessor(List<Aspect> aspects) {
        this.aspects = aspects;
    }

    @Override
    public Object processAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof Aspect) {
            return bean;
        }
        return ProxyUtil.createProxy(bean, aspects);
    }

}
